package com.example.myapplication.view;

import com.example.myapplication.QueryJson2;
import com.example.myapplication.shortvideo.utils.GsonUtil;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2020/12/21
 * @description
 */
public class CreatJson1 {
    public static void main(String[] args) {
        String path = "D:/wrf/qn";
        String outpath = "D:/wrf/juzi.json";
        File file = new File(path);
        File[] list = file.listFiles();

        List<QueryJson2.Query1.Bean> beans = init();
        List<Bean> beanList = new ArrayList<>();
        Bean bean;
        // 如果目录下文件存在
        if (file.exists() && file.isDirectory()) {
            for (int i = 0; i < list.length; i++) {
                String name = list[i].getName();
                int index = name.indexOf(".");
                String name3 = name.substring(0, index);
                for (int j = 0; j < beans.size(); j++) {
                    if (beans.get(j).url.equals(name3)) {
                        bean = new Bean(beans.get(j).name, name3);
                        beanList.add(bean);
                        break;
                    }
                }
            }
        }
        try {
            String json = GsonUtil.toJson(beanList);
            BufferedWriter out = new BufferedWriter(new FileWriter(new File(outpath)));
            out.write(json);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static class Bean {
        public String class_name;
        public String path;

        public Bean(String class_name, String path) {
            this.class_name = class_name;
            this.path = path;
        }
    }

    public static List<QueryJson2.Query1.Bean> init() {
        List<QueryJson2.Query1.Bean> list = new ArrayList<>();
        list.add(new QueryJson2.Query1.Bean("weimei", "唯美的句子"));
        list.add(new QueryJson2.Query1.Bean("zheli", "哲理的句子"));
        list.add(new QueryJson2.Query1.Bean("aiqing", "爱情的句子"));
        list.add(new QueryJson2.Query1.Bean("xinsui", "心碎的句子"));
        list.add(new QueryJson2.Query1.Bean("xinfan", "心烦的句子"));
        list.add(new QueryJson2.Query1.Bean("anlian", "暗恋的句子"));
        list.add(new QueryJson2.Query1.Bean("shiwang", "失望的句子"));
        list.add(new QueryJson2.Query1.Bean("xiangni", "想你的句子"));
        list.add(new QueryJson2.Query1.Bean("maren", "骂人的句子"));
        list.add(new QueryJson2.Query1.Bean("shuqing", "抒情的句子"));
        list.add(new QueryJson2.Query1.Bean("youmei", "优美的句子"));
        list.add(new QueryJson2.Query1.Bean("lizhi", "励志的句子"));
        list.add(new QueryJson2.Query1.Bean("youqing", "友情的句子"));
        list.add(new QueryJson2.Query1.Bean("xinsuan", "心酸的句子"));
        list.add(new QueryJson2.Query1.Bean("xinlei", "心累的句子"));
        list.add(new QueryJson2.Query1.Bean("shilian", "失恋的句子"));
        list.add(new QueryJson2.Query1.Bean("wunai", "无奈的句子"));
        list.add(new QueryJson2.Query1.Bean("xiangjia", "想家的句子"));
        list.add(new QueryJson2.Query1.Bean("gaoxiao", "搞笑的句子"));
        list.add(new QueryJson2.Query1.Bean("shiyi", "诗意的句子"));
        list.add(new QueryJson2.Query1.Bean("shanggan", "伤感的句子"));
        list.add(new QueryJson2.Query1.Bean("jingdian", "经典的句子"));
        list.add(new QueryJson2.Query1.Bean("qinqing", "亲情的句子"));
        list.add(new QueryJson2.Query1.Bean("xintong", "心痛的句子"));
        list.add(new QueryJson2.Query1.Bean("xinjing", "心静的句子"));
        list.add(new QueryJson2.Query1.Bean("biaobai", "表白的句子"));
        list.add(new QueryJson2.Query1.Bean("nanguo", "难过的句子"));
        list.add(new QueryJson2.Query1.Bean("sinian", "思念的句子"));
        list.add(new QueryJson2.Query1.Bean("xianshi", "现实的句子"));
        list.add(new QueryJson2.Query1.Bean("huiyi", "回忆的句子"));
        return list;
    }
}
